package com.qsmx.store.app.util;

import android.app.Activity;
import android.app.Presentation;
import android.content.Context;
import android.hardware.display.DisplayManager;
import android.os.Build;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

import com.qsmx.store.app.main.display.CardPayDisplay;
import com.qsmx.store.app.main.display.CoinPayDisplay;
import com.qsmx.store.app.main.display.DefaultDisplay;
import com.qsmx.store.app.main.display.GiftPayDisplay;
import com.qsmx.store.app.main.display.GoodsPayDisplay;
import com.qsmx.store.app.main.display.PayDisplay;
import com.qsmx.store.app.main.display.TurnCardDisplay;

import java.util.ArrayList;
import java.util.Map;

public class DisplayUtil {

    /**
     * 隐藏虚拟按键，并且全屏
     */
    public static void hideBottomNav(Activity activity) {
        View decorView = activity.getWindow().getDecorView();
        decorView.setSystemUiVisibility(0);
        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN |
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);
    }


    /**
     * 关闭Android导航栏，实现全屏
     */
    public static void closeBar() {
        try {
            String command;
            command = "LD_LIBRARY_PATH=/vendor/lib:/system/lib service call activity 42 s16 com.android.systemui";
            ArrayList<String> envlist = new ArrayList<String>();
            Map<String, String> env = System.getenv();
            for (String envName : env.keySet()) {
                envlist.add(envName + "=" + env.get(envName));
            }
            String[] envp = envlist.toArray(new String[0]);
            Process proc = Runtime.getRuntime().exec(
                    new String[]{"su", "-c", command}, envp);
            proc.waitFor();
        } catch (Exception ex) {
            // Toast.makeText(getApplicationContext(), ex.getMessage(),
            // Toast.LENGTH_LONG).show();        }
        }
    }

    public static Display[] getDisplays(Context mContext) {
        DisplayManager mDisplayManager;//屏幕管理类
        mDisplayManager = (DisplayManager) mContext.getSystemService(Context.DISPLAY_SERVICE);
        return mDisplayManager.getDisplays();
    }

    public static Presentation showDefaultDisplay(Context mContext) {
        DefaultDisplay display = new DefaultDisplay(mContext, DisplayUtil.getDisplays(mContext)[1]);
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
            display.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
        } else {
            display.getWindow().setType(WindowManager.LayoutParams.TYPE_PHONE);
        }

        if (!display.isShowing()) {
            display.show();
        }

        return display;
    }

    public static Presentation showPayDisplay(Context mContext) {
        PayDisplay display = new PayDisplay(mContext, DisplayUtil.getDisplays(mContext)[1]);
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
            display.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
        } else {
            display.getWindow().setType(WindowManager.LayoutParams.TYPE_PHONE);
        }

        if (!display.isShowing()) {
            display.show();
        }

        return display;
    }

    public static Presentation showPayCoinDisplay(Context mContext) {
        CoinPayDisplay display = new CoinPayDisplay(mContext, DisplayUtil.getDisplays(mContext)[1]);
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
            display.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
        } else {
            display.getWindow().setType(WindowManager.LayoutParams.TYPE_PHONE);
        }

        if (!display.isShowing()) {
            display.show();
        }

        return display;
    }

    public static Presentation showPayCardDisplay(Context mContext) {
        CardPayDisplay display = new CardPayDisplay(mContext, DisplayUtil.getDisplays(mContext)[1]);
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
            display.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
        } else {
            display.getWindow().setType(WindowManager.LayoutParams.TYPE_PHONE);
        }

        if (!display.isShowing()) {
            display.show();
        }

        return display;
    }

    public static Presentation showPayGoodsDisplay(Context mContext) {
        GoodsPayDisplay display = new GoodsPayDisplay(mContext, DisplayUtil.getDisplays(mContext)[1]);
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
            display.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
        } else {
            display.getWindow().setType(WindowManager.LayoutParams.TYPE_PHONE);
        }

        if (!display.isShowing()) {
            display.show();
        }

        return display;
    }

    public static Presentation showPayGiftDisplay(Context mContext) {
        GiftPayDisplay display = new GiftPayDisplay(mContext, DisplayUtil.getDisplays(mContext)[1]);
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
            display.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
        } else {
            display.getWindow().setType(WindowManager.LayoutParams.TYPE_PHONE);
        }

        if (!display.isShowing()) {
            display.show();
        }

        return display;
    }

    public static Presentation showMemCardTurnDisplay(Context mContext) {
        TurnCardDisplay display = new TurnCardDisplay(mContext, DisplayUtil.getDisplays(mContext)[1]);
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
         } else {
            display.getWindow().setType(WindowManager.LayoutParams.TYPE_PHONE);
        }

        if (!display.isShowing()) {
            display.show();
        }

        return display;
    }

}
